//this file cleans our enrollment outcome data

global direc "[YOUR PATH HERE]"
global data "${direc}/data"


********************************************************************************
**ENROLLMENT DATA**
********************************************************************************

use "${data}/clean_ipeds_enrollment.dta", clear

//fill in any missing control var based on previous year control
sort unitid file_year
by unitid : egen new_cont = mode(control)
	drop control 
	rename new_cont control
	
//generate flag for minority serving institutions
foreach s in hbcu pbi annhi tribal aanapii hsi nanti{
	sort unitid file_year
	by unitid : egen new`s' = max(`s')
		drop `s'
		rename new`s' `s'
}
gen msu = 0
foreach s in hbcu pbi annhi tribal aanapii hsi nanti{
	replace msu = 1 if (`s')
}

//fill in missing locales
sort unitid file_year
by unitid : egen new_loc = max(locale)
	drop locale 
	rename new_loc locale
gen urban = (locale == 11 | locale == 12 | locale == 13)

//fill in any missing states and cities
sort unitid file_year
by unitid : egen new_st = mode(st_fips)
	drop st_fips 
	rename new_st st_fips
by unitid : egen new_city = mode(city)
	drop city 
	rename new_city city

//generate school classifications
 gen deg = 1 if iclevel == 2
	replace deg = 3 if iclevel == 1
 
 replace deg = 1 if highdeg == 2 & missing(deg) //aa schools
		drop if highdeg < 2 & !missing(highdeg)
 replace deg = 3 if highdeg >= 3 & preddeg > 2    //four-years
 replace deg = 1 if (preddeg <= 2 & highdeg > 2)  //ccba schools
 
 bysort unitid: egen new_deg = min(deg)
	drop deg
	rename new_deg deg

save "${data}/outcomes_enrollment.dta", replace
